using CfgTable;
using IQIGame.Onigao.Framework;
using IQIGame.Onigao.Game;

namespace IQIGame.Onigao.GamePlay
{
    public class UIN_HeroUpItem : UIBaseNode
    {
        #region Template Generate,don't modify
        protected class UIB_UIN_HeroUpItem
        {
            #region ObjectBinding Generate
            public IQIGame.Onigao.Framework.ExText textHave { protected set; get; }
            public IQIGame.Onigao.Framework.ExText textCost { protected set; get; }
            public IQIGame.Onigao.Framework.ExImage icon { protected set; get; }
            public UnityEngine.GameObject empty { protected set; get; }
            public UnityEngine.GameObject data { protected set; get; }
            public virtual void InitBinding(ObjectBinding __binding)
            {
                __binding.TryGetVariableValue<IQIGame.Onigao.Framework.ExText>("textHave", out var __tbv0);
                this.textHave = __tbv0;
                __binding.TryGetVariableValue<IQIGame.Onigao.Framework.ExText>("textCost", out var __tbv1);
                this.textCost = __tbv1;
                __binding.TryGetVariableValue<IQIGame.Onigao.Framework.ExImage>("icon", out var __tbv2);
                this.icon = __tbv2;
                __binding.TryGetVariableValue<UnityEngine.GameObject>("empty", out var __tbv3);
                this.empty = __tbv3;
                __binding.TryGetVariableValue<UnityEngine.GameObject>("data", out var __tbv4);
                this.data = __tbv4;
            }
            #endregion ObjectBinding Generate 
        }
        #endregion Template Generate,don't modify

        #region fields



        #endregion fields

        #region properties

        protected UIB_UIN_HeroUpItem ui { get; set; }
        protected UIMsgDispatcher uiMsgDispatcher => this._msgDispatcher as UIMsgDispatcher;

        #endregion properties

        protected override void BeforeInit()
        {
            ui = new UIB_UIN_HeroUpItem();
            ui.InitBinding(this.csObjBind);
        }

        protected override void OnInit()
        {

        }

        protected override void OnShow()
        {

        }

        protected override void OnHide()
        {

        }

        /// <summary>
        /// 添加UGUI侦听
        /// </summary>
        protected override void AddUGUIListener()
        {

        }

        /// <summary>
        /// 添加全局侦听（MsgDispatcher）
        /// </summary>
        protected override void AddMsgListeners()
        {

        }

        protected override void OnDispose()
        {

        }

        #region methonds

        public void Show(int itemCid, int cost)
        {
            Show();
            if (itemCid == 0)
            {
                this.ShowEmpty();
                return;
            }
            CfgItem cfgItem = TableCenter.item.Get(itemCid);
            if (cfgItem == null)
            {
                Hide();
                return;
            }
            this.ShowData(cfgItem, cost);
        }

        private void ShowData(CfgItem cfgItem, int cost)
        {
            ShowNode(true);
            int numHave = ItemModule.Instance.GetNum(cfgItem.Id);
            this.ui.textCost.text = cost.ToString();
            this.ui.textHave.text = numHave.ToString();
            this.SetImageSprite(this.ui.icon, cfgItem.Icon_fullPath);
        }

        private void ShowEmpty()
        {
            ShowNode(false);
        }

        private void ShowNode(bool isActiveData)
        {
            this.ui.data.SetActive(isActiveData);
            this.ui.empty.SetActive(!isActiveData);
        }

        #endregion methonds
    }
}
